﻿Public Class Drink
    Private _drink_id As Integer
    Private _drink_name_tha As String
    Private _drink_name_eng As String

    Public Property Drink_id() As Integer
        Get
            Return _drink_id
        End Get
        Set(ByVal value As Integer)
            _drink_id = value
        End Set
    End Property

    Public Property Drink_name_tha() As String
        Get
            Return _drink_name_tha
        End Get
        Set(ByVal value As String)
            _drink_name_tha = value
        End Set
    End Property

    Public Property Drink_name_eng() As String
        Get
            Return _drink_name_eng
        End Get
        Set(ByVal value As String)
            _drink_name_eng = value
        End Set
    End Property

    Public Function getDrinkByID(ByVal inDrinkID As Integer) As Drink
        Dim outResult As New Drink()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DrinkByID"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inDrinkID", inDrinkID)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Drink")

        For Each objDr As System.Data.DataRow In objDs.Tables("Drink").Rows
            outResult.Drink_id = objDr.Item("drink_id").ToString()
            outResult.Drink_name_tha = objDr.Item("drink_name_tha").ToString()
            outResult.Drink_name_eng = objDr.Item("drink_name_eng").ToString()
        Next

        Return outResult
    End Function

    Public Function getDrinkByNameTha(ByVal inNameTha As String) As Drink
        Dim outResult As New Drink()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_DrinkByNameTha"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inNameTha", inNameTha)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Drink")

        For Each objDr As System.Data.DataRow In objDs.Tables("Drink").Rows
            outResult.Drink_id = objDr.Item("drink_id").ToString()
            outResult.Drink_name_tha = objDr.Item("drink_name_tha").ToString()
            outResult.Drink_name_eng = objDr.Item("drink_name_eng").ToString()
        Next

        Return outResult

    End Function

    Public Function getAllDrink() As List(Of Drink)
        Dim outResult As New List(Of Drink)
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_AllDrink"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Drink")

        For Each objDr As System.Data.DataRow In objDs.Tables("Drink").Rows
            Dim obj As New Drink()
            obj.Drink_id = objDr.Item("drink_id").ToString()
            obj.Drink_name_tha = objDr.Item("drink_name_tha").ToString()
            obj.Drink_name_eng = objDr.Item("drink_name_eng").ToString()
            outResult.Add(obj)
        Next

        Return outResult

    End Function

End Class
